package ${projectDefinitionDO.serverProjectDefinitionDO.serverProjectStartClassPackagePathName}.config;

import org.junit.jupiter.api.Test;
import org.web.projectStandardPlatform.client.buildProject.domain.PropertiesDefinitionDO;
import org.web.projectStandardPlatform.client.helper.PropertiesParseHelper;

import java.io.InputStream;
import java.util.*;
import java.io.File;

public class TestParseConfig {

private static final Class[] CONFIG_CLASS_LIST = (Class[]) Arrays.asList(Config1.class, HelloWorldServerStarterConfig.class).toArray();

    @Test
    public void testBuildConfigInfo() throws Exception {
        File file = new File("");
        String outFile = file.getAbsoluteFile()+File.separator+"target"+File.separator+"01.xls";
        String fileName = "D:\\Study\\Back-end\\04.xls";
        List<PropertiesDefinitionDO> list = PropertiesParseHelper.parsePropertiesDefinition(CONFIG_CLASS_LIST);
        PropertiesParseHelper.buildExcelForProperties(outFile, list);
        System.out.println("end");
    }

    @Test
    public void testCompareProperties2JavaConfig() throws Exception {
        List<PropertiesDefinitionDO> list = PropertiesParseHelper.parsePropertiesDefinition(CONFIG_CLASS_LIST);
        String[] propertiesArrasy = (String[]) Arrays.asList("application").toArray();

        List<String> keyNameListInProperties = new ArrayList<>();
        for (String bundleName : propertiesArrasy) {
            Properties properties = new Properties();
            // 使用ClassLoader加载properties配置文件生成对应的输入流
            InputStream in = TestParseConfig.class.getClassLoader().getResourceAsStream(bundleName + ".properties");
            // 使用properties对象加载输入流
            properties.load(in);
            //获取key对应的value值


            Set<Object> sets = properties.keySet();
            for (Object keyName : sets) {
                keyNameListInProperties.add(keyName.toString());
            }
        }

        List<String> listForParseJavaConfig = new ArrayList<>();
        for (PropertiesDefinitionDO propertiesDefinitionDO : list) {
            listForParseJavaConfig.add(propertiesDefinitionDO.getPropertyKey());
        }

        List<String> notContainList = new ArrayList<>();
            for (String key : keyNameListInProperties) {
                if (!listForParseJavaConfig.contains(key)) {
                    notContainList.add(key);
                }
            }
            if (notContainList.size() != 0) {
                System.out.println("Here are some property are not set in Java Config...");
                System.out.println("the total in properties num is " + keyNameListInProperties.size());
                System.out.println("the total in Java Config num is " + list.size());
                for (String key : notContainList) {
                System.out.println(key);
                }
            }
        }
}